<?php 

#	Fastfoo - CMS developer under CakePHP / http://fast-foo.com
#	Copyright (C) 2010  Antonio Irlandés García

#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.

#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.

#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
*
* Encargada de realizar una busqueda de los plugins instalados y configurarlos
* para sus distintos usos dentro del CMS
*
*/


class PluginsComponent extends Object {

	//componentes a usar
	public $components = array('Yaml');

	//ruta de los plugins
	public $path_plugins;
	//Nombre por defecto de los archivos YML
	public $name_yml = 'init.yml';
	//array con las opciones de los plugins recogidas
	public $options_plugins;

	/**
	 * Inicializa la clase y con ella los plugins
	 */

	public function initialize(){
		//ruta de los plugins
		$this->path_plugins = APP.'plugins';
		//recorre los ficheros de configuracion
		$this->_getFilesYML();
	}

	/**
	 * Recorre la carpeta plugins en busca de los archivos YML
	 */
	private function _getFilesYML(){
		
		//Accedo al directorio de plugins
		if (is_dir($this->path_plugins)){

			if ($directory = opendir($this->path_plugins)){
				//Recorro en busca de las carpetas de los distintos plugins
				while(($file = readdir($directory)) !== false){
					//Si es un plugins busco dentro de el el archivo YML
					if (is_dir($this->path_plugins.'/'.$file) && $file!="." && $file!=".."){
						$this->options_plugins[$file] = $this->Yaml->parseFile($this->path_plugins.'/'.$file.'/'.$this->name_yml);
					}
				}
				closedir($directory);
			}

		}else{
			return false;
		}

	}


}
?>
